// 1785. 构成特定和需要添加的最少元素
/**
 * @param {number[]} nums
 * @param {number} limit
 * @param {number} goal
 * @return {number}
 */
/* 
    若 limit 整除 diff 答案是 diff/limit
    若 limit 不整除 diff 答案是 diff/limit + 1
    以上两种情况可以用一个表达式来计算  diff + limit - 1 / limit

*/
var minElements = function (nums, limit, goal) {
	const sum = nums.reduce((prev, next) => prev + next)
	const diff = Math.abs(sum - goal)
	return Math.floor((diff + limit - 1) / limit)
}
const res = minElements([-1, 0, 1, 1, 1], 1, 771843707)
console.log('minElements :>>', res)
